#include <iostream>
using namespace std;

#define max(a,b) (a>b?a:b)

int V, N;
int DP[32][20010];

int main() {
	cin >> V >> N;
	for (int i=1; i<=N; i++) {
		int vi;
		cin >> vi;
		for (int v=0; v<=V; v++) {
			if (v < vi) {
				DP[i][v] = DP[i-1][v];
			} else {
				DP[i][v] = max(DP[i-1][v], DP[i-1][v-vi]+vi);
			}
		}
	}
	int vmax = 0;
	for (int i=1; i<=N; i++) {
		//cout << i << ": " << DP[i][V] << endl;
		vmax = max(vmax, DP[i][V]);
	}
	//cout << vmax << endl;
	cout << V-vmax << endl;
	return 0;
}
